<%--
  Created by IntelliJ IDEA.
  User: 42243
  Date: 2021/4/5
  Time: 13:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*"
         contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.cn.Dao.NewsclassDao" %>
<%@ page import="com.cn.entity.Newsclass" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%
    List<Newsclass> newsclasses=new NewsclassDao().findAll();
%>
<!DOCTYPE HTML>
<html>
<head>
    <title>添加报刊</title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/web.css"/>
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/img/logo2.png" type="image/x-icon">
</head>
<body>
<style>
    #box{
        width: 300px;
        height: 407px;
        border: 2px solid #858585;
        position:absolute;
        right:150px;
        bottom: 350px;
    }
    #imgshow{
        width: 100%;
        height: 100%;
    }
</style>
<jsp:include page="WEB-INF/header/header-admin.jsp"/>
<%
    Object message = request.getAttribute("message");
    if (message != null && message!=""){
%>
<script type="text/javascript">
    alert("<%=message%>")
</script>
<%}%>
<%request.setAttribute("message","");%>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <form role="form" method="post" action="addbooks" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="Inputnum">
                       报刊编号：
                    </label>
                    <input class="form-control" id="Inputnum" name="number" style="width: 40%"/>
                </div>
                <div class="form-group">
                    <label for="InputName">
                        报刊名:
                    </label>
                    <input class="form-control" id="InputName" name="newsname" style="width: 40%"/>
                </div>
                <div class="form-group">
                    <label>
                        报刊种类：
                    </label>
                <select id="class" name="id">
                    <option selected></option>
                    <%for(int i=0;i<newsclasses.size();i++){%>
                    <option value="<%=newsclasses.get(i).getId()%>"><%=newsclasses.get(i).getNclass()%></option>
                    <%}%>
                </select>
                </div>
                <div class="form-group">
                    <label>
                        出版社：
                    </label>
                    <input class="form-control" id="Inputpub" name="pub" style="width: 40%">
                </div>
                <div class="form-group">
                    <label>
                        刊期：
                    </label>
                    <select name="term">
                        <option selected></option>
                        <option value="1" >日报</option>
                        <option value="2" >周刊</option>
                        <option value="3" >半月刊</option>
                        <option value="4" >月刊</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>
                        报刊简介：
                    </label>
                    <textarea  class="form-control" id="Inputinfo" name="info" style="width: 60%;height: 85%"></textarea>
                </div>
                <div class="form-group">
                    <label>
                        定价：
                    </label>
                    <input type="number" class="form-control" name="price" id="Inputpri" style="width: 10%">
                </div>
                <div class="form-group">
                    <label for="file">
                        Picture input
                    </label>
                    <input type="file" name="file" id="file" accept="image/*" onchange="document.getElementById('filepath').value=this.value"/>
                    <input type="hidden" name="filepath" id="filepath" value=""/>
                    <div id="box">
                        <img id="imgshow" data-src="http://ww2.sinaimg.cn/large/6eba2496gw1f3uya0kdfej20hs0b440w.jpg" alt=""/>
                    </div>
                    <p class="help-block">
                        Please upload the cover of the new newspaper here.
                    </p>
                </div>
                <button type="submit" class="btn btn-primary" >
                    Submit
                </button>
            </form>
        </div>
    </div>
</div>


<script>
    $('#file').change(function(){
        var file = $('#file').get(0).files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload=function(e){
            console.log(e);
            $('#imgshow').get(0).src = e.target.result;
        }
    })
</script>

</body>
</html>
